﻿using System.Collections.Generic;
using System.Data;
using System;

namespace ZHDJ.MobileInterface
{
    public partial class PartyQuestionNaireSubimt : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyQuestionNaireSubimtOutParam result = new PartyQuestionNaireSubimtOutParam();
            PartyQuestionNaireSubimtInParam param = new PartyQuestionNaireSubimtInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as PartyQuestionNaireSubimtInParam;

                if (string.IsNullOrEmpty(param.Survey_id))
                {
                    result.code = "0";
                    result.desc = "问卷ID不能为空";

                    isFlag = false;
                }
                //if (string.IsNullOrEmpty(param.Title_Id))
                //{
                //    result.code = "0";
                //    result.desc = "标题ID不能为空";

                //    isFlag = false;
                //}
                if (string.IsNullOrEmpty(param.option_ids))
                {
                    result.code = "0";
                    result.desc = "选项ID集合不能为空";

                    isFlag = false;
                }
                //if (string.IsNullOrEmpty(param.Total_pages))
                //{
                //    result.code = "0";
                //    result.desc = "标题条数不能为空";

                //    isFlag = false;
                //}
                //if (string.IsNullOrEmpty(param.Total_pages))
                //{
                //    result.code = "0";
                //    result.desc = "标题条数不能为空";

                //    isFlag = false;
                //}

                if (isFlag)
                {
                    string[] oids = param.option_ids.Split(';');
                    string id = StringHelper.NewID;
                    isFlag =InterfaceHelper.QuestionNaireTopicSubimt(id, param.Survey_id, param.Title_Id, oids);
                    if (isFlag)
                    {
                        result.desc = "问卷提交成功！";
                    }
                    else
                    {
                        result.desc = "问卷提交失败，请重新提交！";
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-PartyQuestionNaireSubimt", SerializeHelper.JsonSerializer<PartyQuestionNaireSubimtInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyQuestionNaireSubimtInParam, PartyQuestionNaireSubimtOutParam>();
            else
                SafeProcessRequest<PartyQuestionNaireSubimtInParam, PartyQuestionNaireSubimtOutParam>();
        }
    }

    #region 请求参数
    public class PartyQuestionNaireSubimtInParam
    {
        /// <summary>
        /// 必填 调查ID
        /// </summary>
        public string Survey_id
        { get; set; }

        /// <summary>
        /// 必填 标题ID集合
        /// </summary>
        public string Title_Id
        { get; set; }

        /// <summary>
        /// 必填 选项ID集合 多选的以英文分号分隔
        /// </summary>
        public string option_ids
        { get; set; }

        /// <summary>
        /// 必填 标题条数
        /// </summary>
        //public string Total_pages
        //{ get; set; }

    }
    #endregion

    #region 结果参数
    public class PartyQuestionNaireSubimtOutParam
    {
        public PartyQuestionNaireSubimtOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }

    #endregion
}